'use strict';
var clientWidgets = angular.module('clientWidgets');
var clientApp = angular.module('clientApp');

clientApp.directive('slideWidget', ['$rootScope', 'Constant', 'Util', 'DomUtil', 'WidgetUtil',
    function($rootScope, Constant, Util, DomUtil, WidgetUtil) {

    return {
        templateUrl: '/ext/themes/flat/widget/list/slide/view/main.html',
        replace: true,
        //transclude: true,
        restrict: 'E',
        scope: {
            vo: '=vo',
            propMap: '=propModel'
        },
        link: function(scope, element, attrs) {
            scope.$watch('vo', function (newVal, oldVal) {
                if (newVal) {
                    scope.items = WidgetUtil.convert(scope.vo, scope.propMap);
                    console.log(scope.items);
                    var height = Util.computerElemHeight(attrs.uiHeight, Util.getScreenSize().h - 51);

                    setTimeout(function() {
                        var images = $('.io-56-wdg-slide .swipe .swipe-wrap .image');
                        images.css('height', height);
                        images.css('width', Util.getScreenSize().w + 'px');

                        window.mySwipe = Swipe(document.getElementById('io-56-wdg-slide-swipe'), {
                            startSlide: 0,
                            speed: 400,
                            auto: 1000,
                            continuous: true,
                            disableScroll: false,
                            stopPropagation: false,
                            callback: function(index, elem) {},
                            transitionEnd: function(index, elem) {}
                        });
                    }, 10);

                }
            });
        }
    };
}]);

